|
|
 |
|
|
|
|
Print #mintHandle, strWrite & vbCrLf
WriteLine = True
End If
End Function |
|
|
|
|
|
|
|
|
You can see that you use the Print statement with the file handle number you retrieved from the Class_Initialize() event. Print is a built-in statement in Visual Basic thats used to write information to a file. |
|
|
|
|
|
|
|
|
Once the write process is finished, the file should be closed. The sample TextStream class implements a CloseFile() method to close the file handle: |
|
|
|
 |
|
|
|
|
Public Function CloseFile() As Boolean
' Valid File Handle ?
If mintHandle <> 0 Then
Close #mintHandle
mintHandle = 0
CloseFile = True
Else
CloseFile = False
End If
End Function |
|
|
|
|
|
|
|
|
The CloseFile() method first checks the file handle to see whether its valid. Any number other than 0 is a valid file handle. CloseFile() then calls the Close statement to close the particular file handle stored in the object. It also sets the file handle to 0; this way, if any other methods are called after the file is closed, no errors will occur. In every method of this class, the file handle is checked to see whether its valid prior to performing any operation on the file. |
|
|
|
|
|
|
|
|
Now that youve seen how to write information into a file, lets look at how to read information out of a file. You still use the TextStream class to accomplish this, but you simply use other methods of the class for reading the file. |
|
|
|
|
|